• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Item Trading overhaul

With the new itemtrading characters and sets of items coming out--Cat's Sneaky Trader, Alan Smithee's Apothecary, Opium den, etc., we need a way to give only certain items to certain traders.

So, why not, I'm proposing overhauling the item trading backend (the interface is fine SFAIK).

First change: add checks for `item-specific` and `trader-specific` item trade type attributes.
Both items and traders could each have multiple types.

Format:
item.itemtradetypes or NPChar.itemtradetypes
*.qty = number of types
*.type1 = "some trade type string" -- like "stolen", "general", "weapons", etc...

If no type found, default to general or something.

Next, have persistent inventories. At game start, fill inventory normally. Then, each day, do a couple of removals and a couple of additions. Also track money, both when the PChar trades with the itemtrader, and when doing daily add/remove of items.
Key both the inventory quality/amount and the base money to the town size. Key rarity to add/removal of inventory.

Eventually give a boost to selling and arriving when fleets are in port (once fleets are added).

Now this would be best when tied to the new iventory system (which would add a primary "`close-to`-hand" inventory along with the current "kept loose in backpack" inventory.

Then, using the above, any character could be a temporary item trader; send the equipment they won't sell to close inv, and make the list of salable items the remaining iventory.


The above changes to make item inventory persistent would also allow real pawning--get some money fast, come back a week later and hopefully the item's still there...

Heh, you could even when removing items from the trader give them to _other_ NPCs, so if you wanted something you pawned back you'd have to find the NPC who has it now and get them to trade it...
 
I like it! So when are you starting? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/laugh.gif" style="vertical-align:middle" emoid="xD:" border="0" alt="laugh.gif" />

Seriously, this is something that would be MOST welcome; and I love the idea of the "pawn"... Very cool... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/yes.gif" style="vertical-align:middle" emoid=":yes" border="0" alt="yes.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" />
 
Excellent idea. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" /> I like "logistical problems" in a game, like not being able to get everything everywhere, or not being able to carry 50 swords with me. So I'd welcome special traders and a (limited) backpack inventory.
I'd even suggest adding a "local" attribute, like "these goods are only produced on that island" or "those items are only made by Spanish craftsmen". Or like "Indian artifacts can only be got from tribesmen in the jungles or from Incan graves, that's why collectors in town pay so much for them"
And maybe a "quality" attribute as well. The vagabonding panhandlers would sell only basic stuff and might have not enough money to buy much of your booty. Only selected master craftsmen on certain islands would have the best items.
Trade, as well as the gameworld, would IMHO be more lively if there were more differences. Right now it makes no difference if you visit a trader in Conceicao port or in the backstreets of Redmond. Alan's specialized "traders"(if you can use that term for drugged tatooists:cheeky) are already a great leap to a more interesting gameworld. As would be your diversified trading system.
But other people will surely have the (quite justified) opinion that this only complicates their fun.
 
Heh, thus the need for a "switch"... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="icon_wink.gif" />

I'd like to see the variety; it makes for a more `true-to`-life experience that the best (whatever) could be found only with the (whichever) nation because they are the ones with the recognized craftstpeople &tc... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/yes.gif" style="vertical-align:middle" emoid=":yes" border="0" alt="yes.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" />
 
Cat: now. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/type_1.gif" style="vertical-align:middle" emoid=":nk" border="0" alt="type_1.gif" />

CCC: Great idea re: local!
Why not coopt the normal/import/export/contraband goods trade types for items?
Re: quality and trader levels: yeah, absolutely! And tie this to town size /wealth* too?

Basically my current goal is to make calculations as `un-current`-`islands-specific` as possible, so if we add a new island and/or towns down the road we just assign a nation and population and the rest `auto-calculates`.

Ah! A thought. IMO best to add said `Indian-ruins`-`on-island` flags and any other island specific flags as flags in the _island defines_ (or town defines as the case may be...), not checking in the item functions for the current island.

That way multiple islands can pull from the same item set.

We can always make things more specific later, i.e. for now just use "Indian" but later if we have room for separate Indian tribes we can have one island having one set, etc.

Well now, here's a project: anyone care to go through the weapons list and set up national flavors? (I.e. CP is clearly British, Conq. is Spanish, and so forth...)

*I really should make wealth and size not so closely coupled...to allow for towns on gold mines or big poor towns...
 
{EDIT: so much for changing from itemtradetype to tradetype; turns out we need the disambiguation. Well, at least I shaved the trailing s off...}


In regards to this and upcoming quests (*cough*Cat*Alan*cough*) just follow the above general guidelines and pretend my code's there.
{I'll have the backend done or at least in alpha by the time you're ready for it, I hope and trust}

For each item you add, if it's not for general use, add:
itm.itemtradetype.qty = n;
where n is the number of specific trade types you're assigning (if items sold by only one person or group, n = 1).
And then
itm.itemtradetype.type1 = "SneakyTrader"; // or whatever the typename you want.

And for each NPChar who will sell the items, do the same. Note if your trader will sell both normal and special, do the following:
ch.itemtradetype.qty = 2;
ch.itemtradetype.type1 = "General";
ch.itemtradetype.type2 = "Apothecary";

or something like that.

Lastly, if you want the check to be based on AND - i.e. _all_ the conditions true, rather than the default, OR - at least one of the conditions true, add
itm.itemtradetype.alltrue = 1;
(or ch.that)
That would mean that, for items, the trader must have all of the item's types, or, for traders, that the item must have all of the trader's types.


A couple other attributes that will help, per CCC's excellent suggestions:
Location:
itm.itemtradetype.loc.qty = n;
itm.itemtradetype.loc.type1 = ITEM_LOC_Type; // see below
itm.itemtradetype.loc.name1 = x;


Where:
{type, name}
ITEM_LOC_LOCATION, the ID of the location (from locations_init) - a string
ITEM_LOC_TOWN, the ID of the town (from towntable.c) - a string
ITEM_LOC_ISLAND, the ID of the island (from islands_init.c, or check the island name given below the town name in towntable.c) - a string
ITEM_LOC_NATION, the nation number - an int (use ENGLAND or PIRATE or whatever).
ITEM_LOC_ISLANDGROUP, the id of the island group (not needed yet)


The same AND/OR switch (*.itemtradetype.loc.alltrue = 1) can be used here.


Note that only items would have loc attributes.

Quality:
itm.itemtradetype.quality = q;

Where q is an int.

and, for traders
ch.itemtradetype.qualitylevels.qty = n;
ch.itemtradetype.qualitylevels.lev1 = q;

So traders can trade in items of multiple levels. Usually it'd be from `1-quality` for big stores, but `small-time` traders may have only 1 level, or an odd mix.

NOTE / Further Idea: the levels need not be in order. Whatever is lev1 will be considered the base quality level of the trader--so a `high-quality` trader may _take_ `low-qual` items but will not pay their full value ("ptah, not worth my time!").
-----------------------------------------

That's the item properties.
Now, for the itemtrade screen (and inventory and itemsbox/officer too, probably).
Should we display the item's quality? (I think so--but maybe only if commerce skill high enough?)
Should we have some way of showing what items are of what types (i.e. so you'll know you can only sell that stolen sword to a fence?)

Lastly we need to add either a pawn button or a sell/pawn switch. Because...
I'll need to add an attribute to the trader, ch.pawned, with a qty and a list of the items pawned, so that when the items are removed from the trader they are given to a townsperson (or removed period--an `out-of`-towner bought it, it got lost, whatever. Not _every_ item would be findable...)
-----------

So, next round of thoughts...?
The floor, she is open. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
 
Whoops, forgot the multipliers (imp/exp/contra).
Use this instead of the first section, for traders and towns/islands/locations (so now the attribute tree for items will _not_ be identical in format to that of traders/locations).
thing.itemtradetype.qty = n;
.itemtradetype.nametype1 = nt1;
.itemtradetype.name1 = x1;
(.itemtradetype.tradetype1 = t1;)
(.itemtradetype.qtymult1 = m1;)
(.itemtradetype.pricemult1 = m1;)
(.itemtradetype.exclusive1 = b1;)
n is the number of these blocks.

Nametype can have one of three values:
"group" - name will be BLADE_ITEM_TYPE or other groupID.
"type" - name will be "SneakyTrader" or other itemtype.
"id" - name will be the ID of a specific item.

name is whatever you want (and of the type you say in nametype).
These two are required for each block. The rest are optional.

tradetype is the trade type: TRADE_TYPE_NORMAL, EXPORT, IMPORT, CONTRA, CONTRA_HIM, CONTRA_YOU. Note that this just sets the type, not the multiplier.
Contraband means it counts as contraband for both of you; CONTRA_HIM means he buys high and sells low; CONTRA_YOU means you buy at high price but sell back at a pittance.

qtymult is the quantity multiplier (0.1, 1.0, 1.75, etc.). Negative numbers mean quantities (-1 means qty=1).

pricemult is the price multiplier. Use in conjunction with tradetype to set a specific price multiplier (i.e. CONTRA_YOU but a low price multiplier means you buy at _normal_ (not contraband) price but sell at an even lower price.

exclusive determines whether, for an item which matches more than one type, the multipliers are multiplied together (itm qty mult = match1.qtymult * match2.qtymult) or whether the excluse=1 tagged block is the only one used.

If omitted, tradetype defaults to NORMAL, and the mults to 1.0 each.

Note: if you _really_ want a trader not to stock an item/type/group, just do not list it (and make sure none of the other things listed include the item!). If you say CONTRA, that means to stock a few (but require the player to have trustworthy/be nice to the trader, whatever).

Example:
SneakyTrader (st).

st.itemtradetype.qty = 1;
st.itemtradetype.nametype1 = "type";
st.itemtradetype.name1 = "SneakyTraderItems";
st.itemtradetype.tradetype1 = TRADE_TYPE_CONTRA_YOU;
st.itemtradetype.qtymult1 = -1;
st.itemtradetype.pricemult1 = 0.1; // or whatever cancels out the contra multiplier.

+++++++++++++++++++++++++++++++++++++++++

OK, this is getting _way_ too complex.

But we need some of this complexity...--the trade type, the qty, the ability to have different groups have different prices and quantities...the idea here being that a French smith would carry "general" items (i.e. everything) at normal quantities (or even somewhat below), and French weapons (categories French, and weapons) at more qty and lower cost.
 
I guess the question becomes, how much do we build in and how much do we do by hand?

For example, that French smith. If we do things by hand, we separate all items into categories and stick to 1 category. So there are French swords and English pistols but no general weapons.
Then we go to each location and, for the item traders in the location, give them the appropriate categories (or to add a bit more, with appropriate multipliers).

The `do-it`-automatically road is to add all these flags and let the engine figure out the multipliers of someone who carriers general items but is French and a blacksmith.
 
I only browsed the code, but this is an awesome idea and here're my suggestions/questions:

So, swords for the most part could only be buyable from blacksmiths or weapons dealers, and then medicine from apothecaries and so on? I could tie all the indian artifacts into my curio, and remove them from the general traders... I don't understand why they're so worthless, except for the `skill-enhancing` ones. I guess no one cared for "antiques" in that age the way we go wild for them here. I'm also going to add a settlement of Karibs to the Animist island sooner or later, so you could get their trinkets there and sell them elsewhere for a profit... as it is now, you can really only do that with cargo goods - buy low, sell high. So extending it to small items (and reducing your carrying ability - I like that. There then could of course be bags you could purchase to carry more, or give it to your officers and risk their death and the loss of those goodies. Or tie this to the stamina bar proposal? - the more junk you're carrying, the more "encumbered" you are?) is cool.
 
In re: inventory, I'll reply to that part in the Inv. thread.

Great idea re: expanding the islands' locations. There's a ton we can add to islands without changing the world map at all (other than to add new locators, town icons, etc.). Oxbay points the way...

OK, here's overhaul idea #2.
Rather than going the `super-duper` complex route I outline above, what about paring it down to:
Give each item _one_ type, and a switch as to whether it will also be counted as "general."
Then, give each trader three attribute trees.
ch.itemstradetype.export, .import, and .normal.
They would pay extra for import, sell export for cheap.

Then add a function to `auto-populate` those trees based on a trader's location (size, nation, etc), and the trader's level.

That way we'd add the complexity above while making the actual _attribute trees_ much simpler.

In trading, we would look first to if the item, or the item group, is listed under import or export; if so, we change the price and qty accordingly. If not, see whether the item, item group, is listed under the trader's normal tree.

We give most all items the general tag, and most all traders the normal.general tag, and then we do specific handling via items' secondary tags and traders' import/export tags.

(We could also add extra types for items, for use in the function that would `auto-populate` traders' type settings, i.e. French items, items from Oxbay's mine, weapons, etc.)

Lastly, we have the import and export item trees sorted by precedence, so if the type matches we use that multiplier and _stop_ looking for further type matches for that item.

I guess rather than import/export/normal, we do a single listing and list the qty and price multipliers, I think that's better (because what about the person who has few goods but at low prices, or vice versa? Or the person who has some goods at 200% qty and some others at 150%? I.e. blacksmiths, who get bonus both from nation and from type)

I think we also have to handle quality separate from just a type. For ease we can give each item a quality, and give traders min and max qualities to stock.

And also a quality scalar to each trader, to account for stores having far more items than the little stalls.

Example
French blacksmith on FdF. Level 5 blacksmith, FDF is moderate sized and mod. wealthy town, store is small (but bigger than a stall!)
Overall qty scalar 1.0x, min quality 2, max quality 6 (bonus from the town size and wealth).
French Weapons at 1.5x qty, 75% price
Weapons at 1.25x 85%
FdF items at 0.25x, 100%
normal items at 0.1x, 100%

Lastly, we similarly sort the list of types for each item from most specific to least specific. That means once we find a match, we needn't look farther.
 
So. On to business.

I can code all this OK, but I'd _really_ like a volunteer to go through and categorize items... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/hi.gif" style="vertical-align:middle" emoid=":gday" border="0" alt="hi.gif" />
 
Can there also be ways to grade what is found in random locations? I'd like to see the rarer items be used in quests instead of whoops, lookit, I found a Solingen Rapier right in the middle of Oxbay town, underneath this tree!!! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> I always felt that it shouldn't be that easy, you know?

I like the #2 overhaul suggestion - for it's (here's that word I love to use) <i>elegance.</i> Too complicated is just not the way to go, here. If we can keep it simple so the coding `NON-geniuses` (like myself) can understand it, then it can be an easier task to mod with and to...

Now I just got REALLY BUSY here, so I can't honestly help much with categorization, but I would like to see a section for "illegal" items or "stolen goods" which can trigger guards to be suspicious of you when you deal with my sneaky trader... You could get searched, and fined or sent to jail overnight to punish you for dealing with such a terrible (LOL!) scoundrel and buying stolen goods, depending upon your luck level naturally, you might get off with a warning or you also might find a corrupt guard (are there such things? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="icon_wink.gif" /> ) who will take a bribe to let you go... Heh...

I'm full of ideas on this... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/william.gif" style="vertical-align:middle" emoid=":will" border="0" alt="william.gif" />

Alan, that whole thing with the native items is a great idea, to be able to buy low and sell high to make your profit... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" />
 
Adding a stolen flag--um. Very difficult to do because of the way POTC handles items.
Either we have to add a complete duplicate set of items (to represent the stolen version) or change how POTC tracks items.

Not that I haven't been mulling it over, mind... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/dev.gif" style="vertical-align:middle" emoid=":d:" border="0" alt="dev.gif" />
 
Well, maybe not stolen copies of regular items, but like contraband types of items - like some SWAK weapons or something? That's a very good idea, very workable (that is, something I myself in my small understanding of the code can picture working)... guards already automatically talk to you sometimes, so add an inventory check in their dialog either for certain items or for some new tag appended to certain items, and they'll be all like, "What's that behind your back?... A grenado? Not legal faire here, buddy!" or somesuch, and like with smuggling on shore, you'll have to pay them off, fight or run away.
 
Hmm.
One way to do this is to simply rewrite the inventory system thusly:
Instead of there being the tree
ch.items.itemid1 = qty1;
-------->.itemid2 = qty2;
(as it is now, with no distinction between items of the same ID)
We would have this:
ch.items.num = number_of_items;
ch.items.item1.id = id of that item;
ch.items.item1.stolen = true if stolen, perhaps even record from where.
ch.items.item1.quality* = float(0.0->1.0)?

And whatever other attributes we can give to items.

*I.e. handle weapon quality like that, rather than separate items for all the different levels.

It would add a fair bit of overhead because while right now we can--wait!

What if we go halfway.
Have the old structure, where the attribute name is still the item ID, but then have a tree with one attribute tree per instance of that item you're carrying _under_ the main itemID attribute.
That way there's less overhead because while right now if we want to check whether a character has an item we just check for the attribute and return the qty, the (top) above method would require paging through the entire list of items.
If we go _this_ method (i.e. do both), we save the search time but still can do item specific attributes.

(Are there any gaping holes I'm overlooking?)
 
MANY of the items my sneaky trader sells MIGHT be stolen. It's why I asked about that. I wanted to see if there was a way that a guard could be suspicious of you if you possess one of these stolen items.

It's like when you catch a pickpocket and they offer you jewelry or a gem to "forget it ever happened". Do you take it? If it's stolen goods, what will happen to you whe you do?

The stolen quality could be random too, perhaps it is stolen, perhaps not... ??? You will never know when you buy it what you are getting...

See how my ST mod was getting complicated??? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />
 
<!--`QuoteBegin-CatalinaThePirate`+--><div class='quotetop'>QUOTE(CatalinaThePirate)</div><div class='quotemain'><!--QuoteEBegin-->.  You could get searched, and fined or sent to jail overnight to punish you for dealing with such a terrible (LOL!) scoundrel and buying stolen goods, depending upon your luck level naturally, you might get off with a warning or you also might find a corrupt guard (are there such things? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="icon_wink.gif" /> ) who will take a bribe to let you go...  Heh...
[/quote]
I can contribute the code for the searching part. Actually it runs already in my trial thief mod: all the formerly lazy townguards do their duty now, patrol the streets and check your "papers". If you run into such a check and happen to be hostile to the towns nation the guards will attack you, unless you succeed in bribing, fooling or threatening the controling guard. That means that sneaking into hostile town now really requires careful sneaking.
It would be easy to include a check for stolen items. IF we can make a stolen flag, that is...
I love these brainstorming discussions here, and all the fascinating ideas, but I at least have already much more ideas on my desk than i can realize <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" />
 
Heh. Me too most definitely. I'm having to make a list just to keep track. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
In re stolen, the above final method will I think work best. We can still do quick item checks (rather than
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if(checkattribute(char, "items.itemid")) return sti(char.items.(itemid));

// we do

if(checkattribute(char, "items.itemid")) return GetAttributesNum(char.items.(itemid));<!--c2--></div><!--ec2-->

And while clunky, for now we can just show _all_ items in inventory and itemstrade (show as to differentiate which are stolen and which not, and which are of which quality).

So. I think this may be ready to code!
 
<!--`QuoteBegin-NathanKell`+--><div class='quotetop'>QUOTE(NathanKell)</div><div class='quotemain'><!--QuoteEBegin-->So. I think this may be ready to code![/quote]Outstanding!

I too, love the brainstorming and exchange of ideas! It's great that the modding forum has become more lively, as we sure do have fun...

I'm glad we're adding things in small chunks, so people can enjoy playing PotC while we work up more new stuff - by the time they get itchy for more, we've got more! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
 
I have good news and bad news.

The good news is, I finished coding the system. Last night, actually, but too tired to post.

The bad news is, it's incredibly slow. I'm going to see what I can do, but in the meanwhile I'll upload an archive of my program folder (it's mostly PB's modpack, with some various changes. BuildSettings.h is bloody huge now, but the itemtrade defines all start IT_ and are near the bottom).

You will need to start a new game.

But the plus side is, items have quality, traders can stock varying item types (although I have not yet assigned types to any items), and traders update once per day, but only those you've already talked to (and made the game generate items for).
 
Back
Top