We shouldn't code and see if we like the gameplay result.
It's funny you should say that because that is normally how I roll
But, I had a feeling this was going to get complicated compared to simply selling a unit's cargo.
Now the big question is if that is what we want from the game.
Well, let's talk it out. If I am deciding I want to set up an AI Trader to buy "specific" things for me what will be the best way to set that up. Normally I am going to want Yields for a Certain city, like if I have a City that is a poor area to farm Barley, but yet I want to start a Rum factory there I will need to supply said city with Barley. The commands could then be placed in the city where we set a Trader Buy Threshold, but what would this Threshold represent? Normally you would want to keep enough Barley in order to keep your current Rum production working at its peak. Therefore, could we simply tell the AI Trader to "keep Rum production up" and then the AI will buy Barley enough to keep the Rum run going, up to max storage? It could actually get technical with this in that in factors how much Barley is being used each turn, how many turns will his venture take, and therefore how much Barley he should buy. Like if the City is nearly full of Barley, but in the 12 turns it will take to buy more and return with it the City will be 50% depleted so therefor plan for the city only having 150 Barley.
We could want the AI Traders to like, buy up Tools and spread them around to several cities, but to keep things simply we should just allow the existing Trade Route logistics to work this part. Our AI Traders then should simply Buy Tools for its Home City, keeping it well stocked so that our Supply Trains can move the Tools around.
We would then need two array settings in City(may can use existing), a Well Stocked Yield array, and a Maintain Production Array. Units will then have two commands for its Home City, one to Keep a City Well Stocked (buy until full, idle, and buy more if stocks start to dwindle), and Maintain Production where the Unit will seek to keep a Yield Stocked to match its production, factoring in travel times, distance, and things like the quickest amount he can get compared to how fast the Yield is being consumed. Like if you has enough Barley for 4 turns of production, but yonder City has more Barley to buy, but if he goes there your City will run out of Barley, so first he drops off his current load before setting out to buy more.
The Gold settings could be something we figure out with testing as I am not sure how that will effect things. Perhaps a command could be setup where you can set a Spending Threshold where once your Gold reserves get to a certain point, Traders are no long allowed to buy, but will sit Idle waiting for the Gold to return to ample amounts.