Barter Zone Filtering, Trade Execution

Hey Folks! Making more progress on the trading system today. The barter zones are now filtering appropriate items, and the first draft of the trade execution code is in.

Today's image is a recreation of yesterday's test, this time with new filtering and flags in place. Items like the floor and walls are ignored, while items that can be transported (like hull patches, gas canisters, and batteries) appear in the list. Furthermore, each line item correctly shows how many units each party has in their collective person and zones.

The next step was to setup some code to do the required item and fund transfers when the user clicks accept. This turned out to be a bit more complicated, as it involved a few steps.

First, we had to check that the buyer/seller had the required funds. A pretty simple stat check.

Then, we had to make sure the buyer/seller had enough room to store the items they purchased. This was a bit more involved.

The assumption, for now, is that all purchased items get transported to the buyer's barter zone(s), and that the vendor has unlimited funds. Then, we start with the vendor buying player items, in case the trade required selling-off player items to fund the transaction. Each item is checked against the zones of the buyer to see if it fits. (I had to write a crude tile-by-tile check for now, similar to ship part placement.) If it fits, the item is moved, and funds are transferred for that item.

If it doesn't fit, the trade is aborted, and an error message appears in the UI to say which item wouldn't fit.

Once the vendor finishes buying, the player starts the same process for their purchases, row-by-row. When all is done, a successful trade closes the UI, funds are fully transferred, and all items are in barter zones for their new owners. In practice, this means the player walks back to their ship, into the cargo area where their barter zone is (for example), and can begin using/installing the items.

As I mentioned, the code for this is all in place now. However, I need a way to test it.

I think I can do a rough test by spawning a bartender or something into the starting area, and setup a barter zone owned by that bartender, another barter zone owned by the player, and then trade.

However, going forward, I'm going to need some way to specify NPC spawns on a ship template, and zones assigned to them. This probably means custom person specs with loadouts for each station, as well as custom station layouts so I can zone them accordingly.

And, as it turns out, I have to resurrect the ship editor. It seems this boatload of new stuff I've been adding is not yet supported in the ship editing mode. (Null references due to missing GUIZone interface, etc.) Fixing that shouldn't be too hard, but I've also been meaning to merge the ship editor with the crew sim mode. It cuts down on this sort of redundant maintenance, but is also means I can see a ship functioning as I build it (e.g. power connections, air flow, etc.).

So that's where things are now. Probably a ShipEdit merge into CrewSim on the docket, plus ship NPC spawning rules, and some custom stations. Could be some fun work for a change!