Misunderstood-Wookiee/Mules-and-Warehouses-Extended

Digging into the Code

Closed this issue · 11 comments

Hey,

I downloaded your mod a couple days ago (great job by the way) and I've been having issues with things like station and supply mules not doing what I expect them to do. I'm sure it's just me skipping over something important. Since I write scripts sometimes during work hours I thought it would be fun to dig into the XML and figure it out for myself.

A lot of it is pretty self explanatory, but I can't seen to find any documentation from Egosoft that points to what the variables reference. I've been able to figure it out for the most part, but this one has stumped me:

<set_value name="$someTrade" exact="$needs.{$nSort}" />

<set_value name="$isTradeWare" exact="$someTrade.owner.tradewares.{$someTrade.ware}.exists" />

<set_value name="$isMadeAndUsed" exact="$someTrade.owner.products.{$someTrade.ware}.exists" />

<do_if value="(not $isMadeAndUsed) and (not $isTradeWare) and $cargoRatio lt 10"> <append_to_list name="$outerList" exact="$someTrade" /></do_if>

What are tradewares and products? I'm assuming tradewares are the initial wares in a factory. Like silicon wafers in a refined metals factory and products are the refined metals. Why are they being excluded from the station mule's potential trade choices if the ware doesn't exist for the buyer and seller priority is false?

Thanks,

Michael

Hello! You'll want to learn how to unpack the game catalog files and get code complete working in an editor in my opinion. After unpacking the game, there is a file called scriptproperties.xml that contains all of the objects and their attributes, with a brief description. This thread is a good starting point:
https://forum.egosoft.com/viewtopic.php?f=181&t=402382

Specifically, here's an example for getting VS code complete working with the unpacked game files:
https://forum.egosoft.com/viewtopic.php?f=181&t=416621

I'm not 100% sure of exactly when something is a tradeware or a product myself. That's not really defined precisely in the scriptproperties xml. But on a warehouse, where there are no production modules, everything seems to be a tradeware. I think on a factory, only the end product is a tradeware. i.e. claytronics on a claytronics factory is a tradeware. Something that I've seen is that a ware can be both a tradeware and a product on a station. They're not mutually exclusive. So I don't know the exact rules for every type of scenario, unfortunately.

The station, distribute, and travel mules were all written by a previous author. The new version of supply mule was written by me. I've tried not to touch the logic in the older mules too much because as far as I've tested, they "just work".

If you have specific questions about how your mules are behaving, I can probably answer that for you. 90% of problems in my experience are user error (though it's hard within the game to communicate to the user what the problem is).

Hm. Okay cool. I'll do that.

As for my own issue I have a claytronics factory (Source) that has buy orders for quantum tubes and microchips. The problem is that my station mule only grabs finished claytronics or antimatter cells and bring them back to the warehouse (Target). The warehouse also has sell offers for tubes and microchips. The two way trade just doesn't seem to be working. I have include food and meds, two way trade, allow low volumes, and make target warehouse checked.

Thanks for the help.

I have not done extensive testing of the two way trade, except to see that it's not erroring out in the logs. Does the source station have a manager and enough budget? This is a really common problem.

How much of the needed item is in the warehouse?

To really figure out what's happening if it's not a simple budget issue, I will have to do a deep dive into the code, add a lot of debug messages, and do a lot of testing. For instance right now I'm thinking perhaps the "$supplies" variable on line 393 doesn't include the things your source station wants.

The way I got started modding X4 just a few weeks ago was having a theory like that, then just trying to figure out all of the details I'd need to print debug it. So, if you get to it before I do, that's fine with me :)

In the meantime, the way I tend to play with mules is a station mule and a supply mule on every factory. The supply mules will help each other out once their own station is supplied. With a low number of stations, it can be good to have a few extra supply mules floating around. I would say in the end of a big empire I have about a 2-1 ratio of supply to station mules. The station mules basically only exist to make warehouses for me.

Yeah. It has a manager and a little over what the suggested budget asks for. There's 10k microchips and 6k tubes in the warehouse.

Haha. That's how I usually debug things anyways. The stuff I work with is pretty old school programming wise. I'll take a look and let you know.

I think that's how I'm going to tackle it. I have a couple other ideas that I'm going to test tonight. It just seems so inefficient. The supply mules seem like a "Throw it against the wall and hope it sticks" solution. They end up not using the warehouses sometimes and that bugs me.

The supply mules just have a very specific order that they work through. It's what I wanted them to do. First look for build storage, then production needs, then fill up warehouses.

Even with player to player trades, they're evaluating "profit", because they're still affecting the prices on those stations by changing the storage levels. But if you want them to heavily favor getting supply from the player, you can change the "player buy mod" slider. At 100 it uses the station manager's price, but lower than that, it reduces it to that percentage. So 0 completely ignores the price on the warehouse and will always source from there as long as there is enough volume to move.

AFAIK product group is the group of wares that are involved in actually producing the product. Primary wares and the actual products are in this category, and I think secondary wares (due to legacy reasons) are also in the product group too.

Then, we have the tradewares group. This group contains wares added via `<add_trade_ware />, and can pretty much be anything (see "set as warehouse").

There should be the 3rd (or 4th?) category but I am not so sure, perhaps that would be the supply group for fleet/ship resupply.

I want to think that these three (four?) groups are mutually exclusive. Not sure if that's how it works.

My memory is that at least once I have seen a ware that was both a tradeware and a product. But it could have been some funny business with the research needs on the PHQ.

That would make sense. I had real issues trying to get things to work using the PHQ. I eventually gave up.

This can all be found in the scriptproperties.xml file?

yes, scriptproperties.xml will tell you all of the attributes available on a trade offer, ware, station, etc. There are other scripts in the unpacked game files that contain information about the builtin functions like find_buy_offer, but IMO those are better off being perused using code completion tools that pop up docstrings and whatnot.

Fair enough. I'm looking at setting that all up now.

I'm going to close this for now but feel free to come back with more questions or contributions!