I started to code up the bartering but ran into a problem cos I only have the list of items per person one at a time. So the longer I do this the more I think Talroth is correct and that I need a general repository of items. Theres a coding technical problem with that with the way I have implemented it so this post is one for the C++ coders.
I was using standard template library (STL) vector class and thats convenient because it overrides the '[' and ']' operators to allow quick indexing ops. Great... but, if you want to specify the location of an item in some array then you need to specify the array and the index for it. There are quite a few of these arrays and so this is a bit of a problem. For example you might have to name all the arrays and then go and search which array you mean via some switch statement. Thats horrible. The obvious solution is to just have a pointer to the item you want to keep track of and screw which array its being held in. So thats what I did when I coded it up. Theres been this nagging little demon sat on my shoulder tho and it keeps reminding me that there is a big big problem with this. The issue is that if I add or remove any item from any array then it might invalidate the pointer because behind STL vector it reallocated the whole array if it gets too big. So pretty much, going with this idea I have to ensure that all items have been added to the array before I start grabbing pointers and I mark items I delete with a tag which says deleted but not actually remove it from the array. So ok cool.
But now I need to get pointers to other peoples items which will change if I now barter stuff so that when I calculate the next guys stuff it will change from the last time. If you see what I mean. Maybe its possible to code around this but I threw the towel in at this point and said oh sod this STL vector crap, it has to go and changed all the code from using the '[' and ']' operators to using the full iterator notation which is a real pain cos its so wordy and kludgy. So once that was done I binned the vector class and switched over to the list class. The advantage of the list class is that it never reallocates the items in the list so you can grab a pointer to them at any time and as long as you don't delete the item then the pointer is safe. But changing items in the list does not affect the other items in the list so all pointers to them are now ok.
I measured the completely unexpected drop in speed. Ok I expected a little drop cos you have to jump via a pointer from one item to the next but in general I am traversing all the items in lists in sequence so I am not continuously running through them in some random order. Perhaps a 2x speed loss. I was totally taken aback when I got about 10,000x speed drop !
So I dunno now. I think something very lame is going on and I may have to drop STL and use my own implementation of lists. I know that I can write a list class maybe a few times slower than vector but not this amount. When I do that then I can have a central repository of items where I can add and delete from it and keep hold of the pointers to items for reference later. I think there's something very broken with the MS STL list class.
So its being worked on a bit but not in the mapping sense for a mo while I get this knocked into shape.